<template>
	<globalModal :title="title" :visible="visible" :confirmLoading="confirmLoading" @ok="handleOk" @cancel="handleCancel">
		<a-spin :spinning="confirmLoading">
			<a-form :form="form" autocomplete="off">
				<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="数据项名称">
					<a-input
						placeholder="数据项名称"
						v-decorator="[
							'itemName',
							{ rules: [{ required: true, message: '请输入数据项名称' }, { max: 50, message: '数据项名称不超过50个字符' }], getValueFromEvent: removeSpaces }
						]"
					/>
				</a-form-item>
				<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="数据项编号">
					<a-input
						placeholder="数据项编码"
						v-decorator="[
							'itemCode',
							{ rules: [{ required: true, message: '数据项编码' }, { max: 20, message: '数据项编码不超过20个字符' }], getValueFromEvent: removeSpaces }
						]"
					/>
				</a-form-item>
				<a-form-item :labelCol="labelCol" extra="数据越小越靠前" :wrapperCol="wrapperCol" label="排序">
					<a-input-number :min="0" class="w100" placeholder="排序" v-decorator="['sortOrder']" />
				</a-form-item>
				<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="数据项状态">
					<a-radio-group v-decorator="['status', { initialValue:'0', rules: [{ required: true, message: '请选择状态' }] }]">
						<a-radio value="0">启用</a-radio>
						<a-radio value="1">停用</a-radio>
					</a-radio-group>
				</a-form-item>
				<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="数据项描述">
					<a-textarea
						placeholder="数据项描述"
						v-decorator="['description', { rules: [{ max: 200, message: '数据项描述不超过200个字符' }], getValueFromEvent: removeSpaces }]"
					/>
				</a-form-item>
			</a-form>
		</a-spin>
	</globalModal>
</template>

<script>
import { sysManageapi } from '@/api/index.js';
import { ModalMixins } from '@/mixins';
export default {
	name: 'addOrEditDicItemtModal',
	mixins: [ModalMixins],
	data() {
		return {};
	},
	created() {},
	methods: {
		//提交保存数据
		handleOk() {
			// 触发表单验证
			this.form.validateFields((err, values) => {
				// 验证表单没错误
				if (!err) {
					/* 处理地址 */
					let parameter = Object.assign({}, values, this.mdl.itemId ? { itemId: this.mdl.itemId } : '', { dictId: this.mdl.dictId, dictCode: this.mdl.dictCode });
					this.saveInfo(this.isAdd ? sysManageapi.dictUrl.addItem : sysManageapi.dictUrl.editItem, parameter);
				}
			});
		}
	}
};
</script>

<style scoped></style>
